package web.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import main.TankSicherheit;

/**
 * Servlet implementation class AdminModulList
 */
public class AdminModulList extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	
	private RequestDispatcher jsp;

	/**
	 * @see HttpServlet#HttpServlet()
	 */

	public void init(ServletConfig config) throws ServletException {
		ServletContext context = config.getServletContext();
		jsp = context.getRequestDispatcher("/WEB-INF/jsp/admin/ModuleList.jsp");
	}
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("doget!");
		request.setAttribute("modulelist", TankSicherheit.modulelist);
		jsp.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String command = request.getParameter("command");
		if(command.equals("start"))
		{
			TankSicherheit.tankSicherheit.startModule(request.getParameter("modul"));
		}
		else if(command.equals("stop"))
		{
			TankSicherheit.tankSicherheit.stopModule(request.getParameter("modul"));
		}
		request.setAttribute("modulelist", TankSicherheit.modulelist);
		jsp.forward(request, response);
	}

}
